package com.gdkj.common;

import com.xjgks.common.constant.HttpResultConstants;
import com.xjgks.common.page.PageInfo;
import com.xjgks.common.response.HttpResult;
import lombok.Data;

import java.io.Serializable;

@Data
public class LogicResult {
    private Integer code;
    private Object data;
    private String message;
    protected Long currentTimeMillis;
    private PageInfo pageInfo;
    
    public LogicResult(Integer code, Object data, String message) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public LogicResult(Integer code, Object data, String message,Long currentTimeMillis) {
        this.code = code;
        this.message = message;
        this.currentTimeMillis = currentTimeMillis;
        this.data = data;
    }

    public LogicResult(Integer code, Object data, String message,PageInfo pageInfo,Long currentTimeMillis) {
        this.code = code;
        this.message = message;
        this.pageInfo = pageInfo;
        this.currentTimeMillis = currentTimeMillis;
        this.data = data;
    }

    public static LogicResult build(Integer code, Object data, String message) {
        return new LogicResult(code, data, message);
    }

    public static HttpResult buildResult(LogicResult baseResult) {
        return new HttpResult(baseResult.getCode(), baseResult.getMessage(), baseResult.getData(), System.currentTimeMillis());
    }

    public static LogicResult paramsError(Object data, String message) {
        return new LogicResult(HttpResultConstants.FAIL_CODE, data, message);
    }

    public static LogicResult buildException(Object data, String message) {
        return new LogicResult(HttpResultConstants.EXCEPTION_CODE, data, message);
    }

    public static LogicResult success(Object data, String message) {
        return new LogicResult(HttpResultConstants.SUCCESS_CODE, data, message);
    }
    public static LogicResult success() {
        return new LogicResult(HttpResultConstants.SUCCESS_CODE, null, "操作成功");
    }

    public static LogicResult success(Object data) {
        return new LogicResult(HttpResultConstants.SUCCESS_CODE, data, "操作成功",System.currentTimeMillis());
    }

    public static LogicResult success(Object data,PageInfo pageInfo) {
        return new LogicResult(HttpResultConstants.SUCCESS_CODE, data, "操作成功",pageInfo,System.currentTimeMillis());
    }

    public static LogicResult fail(Integer code, String message,Object data) {
        return new LogicResult(code, data, message);
    }

    public static LogicResult fail( Integer code, String message) {
        return new LogicResult(code, null, message);
    }
    
    public static LogicResult fail( String message) {
        return new LogicResult(HttpResultConstants.FAIL_CODE, null, message);
    }
    
    
    
}
